<template>
    <el-menu v-if="show" ref="menu" class="leftNav" :default-active="lv3Id&&lv3Id.toString()" :default-openeds="isCollapse?[]:['1']" :collapse="isCollapse">
      <div class="collapse" @click="isCollapse=!isCollapse" :title="isCollapse?'展开':'收起'">
        <i v-if="isCollapse" class="el-icon-d-arrow-right"></i>
        <i v-else class="el-icon-d-arrow-left"></i>
      </div>
      <el-submenu index="1" ref='leftNav'>
        <template slot="title"><i class="el-icon-message"></i><span>{{lv3Menu.name}}</span></template>
        <el-menu-item v-for="child in lv3Menu.child" :index="child.id.toString()" :key="child.id.toString()" @click="handleClick(child.id)">{{child.name}}</el-menu-item>
      </el-submenu>
    </el-menu>
</template>
<script>
  import {mapState, mapMutations} from 'vuex'
  import mapUrl from '@/router/menuUrl'
  export default{
    data () {
      return {
        isCollapse: false
      }
    },
    mounted () {
      this.$bus.$on('menuCollapse', isCollapse => {
        this.isCollapse = isCollapse
      })
    },
    computed: {
      ...mapState(['menu', 'lv2MenuId', 'lv3MenuId', 'lv3Id']),
      show: function () {
        if (this.menu && this.menu[this.lv2MenuId]['child'][this.lv3MenuId].child) {
          return true
        } else {
          return false
        }
      },
      lv3Menu: function () {
        if (this.menu) {
          return this.menu[this.lv2MenuId]['child'][this.lv3MenuId]
        } else {
          return {}
        }
      }
    },
    methods: {
      ...mapMutations(['SET_LV3_MENU']),
      handleClick: function (id) {
      	if(mapUrl[id]){
          this.$router.push(mapUrl[id])
        }else{
          this.$message.info('在研发中...')
        }
        //this.$router.push(mapUrl[id])
      }
    }
  }
</script>
